<template>
  <div class="app-container" style="margin: 30px;">
    <!--查询表单-->
    <el-form :inline="true" class="demo-form-inline">
      <el-form-item>
        <el-input v-model="searchObj.hosname" placeholder="医院名称"/>
      </el-form-item>

      <el-form-item label="创建时间">
        <el-date-picker
          v-model="searchObj.reserveDateBegin"
          type="datetime"
          placeholder="选择开始时间"
          value-format="yyyy-MM-dd HH:mm:ss"
          default-time="00:00:00"
        />
      </el-form-item>
      至
      <el-form-item>
        <el-date-picker
          v-model="searchObj.reserveDateEnd"
          type="datetime"
          placeholder="选择截止时间"
          value-format="yyyy-MM-dd HH:mm:ss"
          default-time="00:00:00"
        />
      </el-form-item>

      <el-button type="primary" icon="el-icon-search" @click="fetchData()" style="width: 100px;height: 40px;">查询
      </el-button>
      <el-button type="default" @click="resetData()" style="width: 100px;height: 40px;">清空</el-button>
    </el-form>
    <!--为echarts准备一个具备大小的容器dom-->
    <div id="main" style="width: 600px;height: 400px;"></div>
  </div>
</template>
<script>
import countApi from '@/api/count'

export default {
  data() {
    return {
      charts: '',
      opinionData: [1, 2, 3, 2, 5, 6],
      xData: ["1", "2", "3", "4", "5"],
      searchObj: {}
    }
  },
  created() {
    countApi.getCountMap(null).then(response => {
      this.opinionData = response.data.countList
      this.xData = response.data.dateList
      console.log("最后生命周期")
      this.$nextTick(function () {
        this.drawLine('main')
      })
    })

  },
  methods: {
    drawLine(id) {
      this.charts = this.$echarts.init(document.getElementById(id))
      this.charts.setOption({
        tooltip: {
          trigger: 'axis'
        },
        legend: { //图表标题
          data: ['预约订单趋势']
        },
        grid: {
          left: '3%',
          right: '4%',
          bottom: '3%',
          containLabel: true
        },

        toolbox: {
          feature: {
            saveAsImage: {}
          }
        },
        xAxis: {
          type: 'category',
          boundaryGap: true, //是否有边界缝隙
          data: this.xData

        },
        yAxis: {
          type: 'value'
        },

        series: [{
          name: '预约订单趋势',
          type: 'line',
          stack: '总量',
          data: this.opinionData
        }]
      })
    },
    fetchData() {
      console.log("searchObj", this.searchObj)
      countApi.getCountMap(this.searchObj).then(response => {
        console.log("点击返回数据", response.data)
        this.opinionData = response.data.countList
        this.xData = response.data.dateList
        console.log("最后生命周期")
        this.$nextTick(function () {
          this.drawLine('main')
        })
      })
    },
    resetData() {
      this.searchObj = null
      this.fetchData()
    }
  },
  //调用
  mounted() {

  }
}
</script>
<style scoped>
* {
  margin: 0;
  padding: 0;
  list-style: none;
}
</style>
